const DateUtils = {

	toDefaultString(date) {
		const dateString = this.toLocalString(date);
		const ms = date.getMilliseconds();
		const milliseconds = ms < 10 ? "00" + ms : (ms < 100 ? "0" + ms : ms);
		return dateString + ":" + milliseconds;
	},

	toLocalString(date) {
		const year = date.getFullYear();
		const month = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
		const hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
		const minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		const seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
	},

	toLocalDateString(date) {
		const dateTimeString = this.toLocalString(date);
		return dateTimeString.substring(0, dateTimeString.indexOf(" "));
	},

	toLocalTimeString(date) {
		const dateTimeString = this.toLocalString(date);
		return dateTimeString.substring(dateTimeString.indexOf(" "), dateTimeString.length).trim();
	},

	getWeekDay(weekDay) {
		let date = weekDay.getTime();
		let startDate = date - 24 * 60 * 60 * 1000;
		let endDate = date + 5 * 24 * 60 * 60 * 1000;
		return [startDate, endDate];
	},

	plusYears(years, date) {
		return new Date((date ? date.getTime() : Date.now()) + 365 * 24 * 60 * 60 * 1000 * years);
	},

	plusMonths(months, date) {
		return new Date((date ? date.getTime() : Date.now()) + 30 * 24 * 60 * 60 * 1000 * months);
	},

	plusWeeks(weeks, date) {
		return new Date((date ? date.getTime() : Date.now()) + 7 * 24 * 60 * 60 * 1000 * weeks);
	},

	plusDays(days, date) {
		return new Date((date ? date.getTime() : Date.now()) + 24 * 60 * 60 * 1000 * days);
	},

	plusHours(hours, date) {
		return new Date((date ? date.getTime() : Date.now()) + 60 * 60 * 1000 * hours);
	},

	plusMinutes(minutes, date) {
		return new Date((date ? date.getTime() : Date.now()) + 60 * 1000 * minutes);
	},

	plusSeconds(seconds, date) {
		return new Date((date ? date.getTime() : Date.now()) + 1000 * seconds);
	},

	minusYears(years, date) {
		return new Date((date ? date.getTime() : Date.now()) - 365 * 24 * 60 * 60 * 1000 * years);
	},

	minusMonths(months, date) {
		return new Date((date ? date.getTime() : Date.now()) - 30 * 24 * 60 * 60 * 1000 * months);
	},

	minusWeeks(weeks, date) {
		return new Date((date ? date.getTime() : Date.now()) - 7 * 24 * 60 * 60 * 1000 * weeks);
	},

	minusDays(days, date) {
		return new Date((date ? date.getTime() : Date.now()) - 24 * 60 * 60 * 1000 * days);
	},

	minusHours(hours, date) {
		return new Date((date ? date.getTime() : Date.now()) - 60 * 60 * 1000 * hours);
	},

	minusMinutes(minutes, date) {
		return new Date((date ? date.getTime() : Date.now()) - 60 * 1000 * minutes);
	},

	minusSeconds(seconds, date) {
		return new Date((date ? date.getTime() : Date.now()) - 1000 * seconds);
	}
};

export default DateUtils;
